import React, { useState,useCallback} from "react";
import { Form, Input, Button } from "antd-mobile";
// import axios from "../utlis/axios";
// import { register } from "../api/user";
import axios from "axios";
import { useNavigate } from "react-router-dom";

// import Three from "../components/Three/Three";

type Props = {};

const Login = (props: Props) => {
  const navigate = useNavigate();
  const onFinish = (values: any) => {
    console.log(values);
    // let res = register("/register", values);
    // console.log(res);
    axios.post("http://localhost:4000/login", values).then((res) => {
      console.log(res);
      if (res.data.code === 200) {
        alert("登录成功");
        window.localStorage.setItem("token", "200");
        navigate("/index/my");
      } else {
        alert("请重新输入密码");
      }
    });
  };
  // function handleClick(captcha: string): void {
  //   throw new Error("Function not implemented.");
  // }

  return (
    <div>
      <Form
        name="form"
        onFinish={onFinish}
        footer={
          <Button block type="submit" color="primary" size="large">
            登录
          </Button>
        }
      >
        <Form.Header>登录页面</Form.Header>
        <Form.Item name="username" label="姓名" rules={[{ required: true }]}>
          <Input placeholder="请输入姓名" />
        </Form.Item>
        <Form.Item name="password" label="密码" rules={[{ required: true }]}>
          <Input placeholder="请输入姓名" />
        </Form.Item>
   
      
      </Form>
        {/* <Three></Three> */}
    </div>
  );
};

export default Login;
